import { apiService } from '../../api/apiService';
import { SearchManuCode, SolutionMode, ServiceMode, getrepairtimebyid } from '../../api/server';
import { selfI18n } from '@/i18n';
// import { showSuccess } from '../../util/MessageDeal';
export function getRepairStatusData () {
    const typeform = {
        servicetype: [],
        solutiontype: []
    };
    // 故障维修状态
    const repairstatus = [
        {
            value: '1',
            label: selfI18n('wp_Pending'),
            text: selfI18n('wp_Pending')
        },
        {
            value: '2',
            label: selfI18n('wp_Processing'),
            text: selfI18n('wp_Processing')
        },
        {
            value: '3',
            label: selfI18n('wp_Be_evaluation'),
            text: selfI18n('wp_Be_evaluation')
        },
        {
            value: '4',
            label: selfI18n('wp_Completed'),
            text: selfI18n('wp_Completed')
        },
        {
            value: 'all',
            label: '所有状态',
            text: '所有状态'
            // label: selfI18n('wp_All'),
            // text: selfI18n('wp_All')
        }
    ];
    // 维检工单状态
    const maintaincheckstatus = [
        {
            value: 'a_processing',
            num: 1,
            index: '1',
            label: selfI18n('wp_Processing'),
            text: selfI18n('wp_Processing')
        },
        {
            value: 'b_waitaccept',
            num: 2,
            index: 2,
            label: '待验收',
            text: '待验收'
        },
        {
            value: 'c_completed',
            num: 3,
            index: 3,
            label: selfI18n('wp_Completed'),
            text: selfI18n('wp_Completed')
        },
        {
            value: '',
            label: '所有状态',
            text: '所有状态'
            // label: selfI18n('wp_All'),
            // text: selfI18n('wp_All')
        }
    ];
    // 维检状态格式化
    const formatmaintaincheckstatus = (val) => {
        const res = maintaincheckstatus.find((item) => item.value === val);
        return res.label;
    };
    // 工单日期快捷选择
    const repairdateseldata = [
        {
            value: '1',
            label: selfI18n('wp_Today'),
            text: selfI18n('wp_Today')
        },
        {
            value: '2',
            label: 7 + selfI18n('wp_Days'),
            text: 7 + selfI18n('wp_Days')
        },
        {
            value: '3',
            label: 30 + selfI18n('wp_Days'),
            text: 30 + selfI18n('wp_Days')
        },
        {
            value: 'custom',
            label: '自定义',
            text: '自定义'
        }
    ];
    // 维修状态耗时显示
    const repairstatustime = [
        {
            value: '1',
            text: '响应超时',
            fontcolor: '#E84026'
        },
        {
            value: '2',
            text: '处理耗时',
            fontcolor: '#E84026'
        },
        {
            value: '3',
            text: '处理耗时',
            fontcolor: '#E84026'
        },
        {
            value: '4',
            text: '处理耗时',
            fontcolor: '#61CFBE'
        }
    ];
    // 服务进度操作类型
    const operatorform = [
        {
            value: '1',
            label: '报修'
            // label: selfI18n('wp_Create')
        },
        {
            value: '2',
            label: selfI18n('wp_Dispatch')
        },
        {
            value: '3',
            label: selfI18n('wp_Accept')
        },
        {
            value: '4',
            label: selfI18n('wp_Transfer')
        },
        {
            value: '5',
            label: '处理'
            // label: selfI18n('wp_Process')
        },
        {
            value: '6',
            label: selfI18n('wp_Evaluation')
        }
    ];
    // 获取设备出场编号列表
    const getManuCode = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: SearchManuCode,
                param: {
                    ...param
                },
                success: (data) => {
                    resolve(data);
                },
                fail: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    // 获取解决方案
    const getSolutionMode = () => {
        apiService({
            api: SolutionMode,
            success: (data) => {
                console.log(data);
            }
        });
    };
    // 获取服务
    const getServiceMode = () => {
        return new Promise((resolve, reject) => {
            apiService({
                api: ServiceMode,
                success: (data) => {
                    resolve(data);
                    data.value.forEach((value) => {
                        typeform.servicetype.push(
                            {
                                value: value,
                                label: value
                            }
                        );
                    });
                },
                fail: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    // 状态格式化
    const repairstatusformat = (item) => {
        const resdata = repairstatus.filter(child => child.value === item);
        if (resdata.length === 0 || resdata === undefined) {
            return item;
        } else {
            return resdata[0].label;
        }
    };
    // 服务进度操作格式化
    const operatortypeformat = (item) => {
        const resdata = operatorform.filter(child => child.value === item);
        if (resdata.length === 0 || resdata === undefined) {
            return item;
        } else {
            return resdata[0].label;
        }
    };
    // 服务进度描述信息分析
    const operatorDescFormat = (child) => {
        const resdata = operatorform.filter(item => item.value === child.operatetype);
        if (resdata.length === 0 || resdata === undefined) {
            return child.operatetype;
        }
        switch (child.operatetype) {
        case '1':
            return (child.operatoralias ? `${child.operator}(${child.operatoralias})` : child.operator) + selfI18n('wp_Created_a_repair_request');
        case '2':
            return (child.operatoralias ? `${child.operator}(${child.operatoralias})` : child.operator) + selfI18n('wp_Send_the_repair_request_to') + (child.receiveralias ? `${child.receiver}(${child.receiveralias})` : child.receiver);
        case '3':
            return (child.operatoralias ? `${child.operator}(${child.operatoralias})` : child.operator) + selfI18n('wp_RR_is_accepted');
        case '4':
            return (child.operatoralias ? `${child.operator}(${child.operatoralias})` : child.operator) + selfI18n('wp_Transfer_this_repair_request_to') + (child.receiveralias ? `${child.receiver}(${child.receiveralias})` : child.receiver);
        case '5':
            return (child.operatoralias ? `${child.operator}(${child.operatoralias})` : child.operator) + selfI18n('wp_Processed_repair_requests');
        case '6':
            return (child.operatoralias ? `${child.operator}(${child.operatoralias})` : child.operator) + selfI18n('wp_Evaluated_repair_requests');
        }
    };
    // 获取工单处理时间
    const gethandletime = (param, callback) => {
        if (param.repairid === undefined) {
            // return '';
        } else {
            apiService({
                api: getrepairtimebyid,
                param: { ...param },
                success: (data) => {
                    // showSuccess($t('wp_Created_successfully'));
                    callback && callback(data);
                }
            });
        }
    };
    // 获取对应状态显示耗时内容
    const getstatustimecont = (status) => {
        const obj = repairstatustime.find((item) => status === item.value) || {};
        return obj;
    };
    // 转换处理时间
    const formathandletime = (val) => {
        if (val > -1 && val < 61) {
            return val + '分钟';
        } else if (val > 60) {
            const htime = Math.trunc(val / 60);
            const mtime = val % 60;
            const time = htime % 24;
            if (htime > 24 && time > 0) {
                const dtime = Math.trunc(htime / 24);
                const newhtime = htime % 24;
                return dtime + '天' + newhtime + '小时' + mtime + '分钟';
            } else {
                return htime + '小时' + mtime + '分钟';
            }
        }
    };
    return {
        repairstatus,
        repairstatusformat,
        operatorform,
        operatortypeformat,
        getManuCode,
        getSolutionMode,
        getServiceMode,
        typeform,
        operatorDescFormat,
        repairstatustime,
        getstatustimecont,
        gethandletime,
        formathandletime,
        repairdateseldata,
        maintaincheckstatus,
        formatmaintaincheckstatus
    };
}
